# -*- ecoding: utf-8 -*-
# @Author: Wick
# @Time: 2024-02-24 21:17


class HouseItem:
    def __init__(self, name, area):
        self.name = name
        self.area = area

    def __str__(self):
        return f"{self.name}占地{self.area}"


class House:
    def __init__(self, house_type, area):
        self.house_type = house_type
        self.area = area
        self.free_area = area
        self.item_list = []

    def __str__(self):
        # Python 能够自动的将一对括号内部的代码连接在一起
        return ("户型：%s\n 总面积：%.2f[剩余：%.2f]\n 家具：%s"
                % (self.house_type, self.area,
                   self.free_area, self.item_list))

    def  add_item(self, item:HouseItem):
        #判断剩余面积是否还可以放家具
        if self.free_area >= item.area:
            self.item_list.append(item.name)
            self.free_area -= item.area
        else:
            print("空间不够，无法再放家具")

bed = HouseItem("席梦思", 4)
chest = HouseItem("衣柜", 2)
table = HouseItem("桌子", 1.5)

print(bed)

print("-"*50)
house = House("两室一厅", 60)
print(house)
house.add_item(bed)
print(house)
house.add_item(chest)
print(house)
